const pool = require('./db.js')
class commentDao {
  // 根据文章id获取评论
  async getComment(id) {
    try {
      const [rows] = await pool.execute(
        `SELECT comments.content, users.username 
         FROM comments 
         JOIN users ON comments.user_id = users.id 
         WHERE article_id = ?`,
        [id]
      );
      return rows;
    } catch (err) {
      console.log('出错:' + err);
    }
  }
}
module.exports = new commentDao()